<template>
	<view class="cart" v-if="cart.length!==0">
		<!-- 收货地址组件 -->
		<my-address></my-address>
		<!-- 标题 -->
		<view class="title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text>购物车</text>
		</view>
		<!-- 商品列表 -->
		
		
		
		<uni-swipe-action>
			<block v-for="(item,index) in cart" :key="index">
				<uni-swipe-action-item :right-options="options" @click="deleteGoods(item)">
					<my-goods :goods="item" :showRadio="true" :showNum="true" @radio-change="radioChange" @num-change="numChange"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		
		<!-- 结算组件 -->
		<my-settle></my-settle>
	</view>
	
	<view class="empty-cart" v-else>
		<image src="/static/cart_empty@2x.png"></image>
		<text>空空如也~</text>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import{mapState, mapMutations} from 'vuex'
	
	export default {
		mixins:[badgeMix],
		computed:{
			...mapState('m_cart',['cart']),
		},
		data() {
			return {
				options:[{
					text:'删除',
					style:{
						backgroundColor:'#C00000'
					}
				}]
			};
		},
		methods:{
			...mapMutations('m_cart',['updateState','updateCount','removeGoods']),
			
			
			radioChange(e){
				this.updateState(e)
			},
			numChange(e){
				this.updateCount(e)
			},
			deleteGoods(goods){
				this.removeGoods(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
.title{
	height: 40px;
	display: flex;
	align-items: center;
	font-size: 14px;
	padding-left: 5px;
	border-bottom: 1px solid #efefef;
	text{
		margin-left: 10px;
	}
}
.cart{
	padding-bottom: 50px;
}
.empty-cart{
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 150px;
	image{
		width: 120px;
		height: 120px;
	}
	text{
		font-size: 15px;
		color: gray;
		margin-top: 15px;
	}
}
</style>
